<template>
	<view>
		<uni-list :border="true">
			<uni-list-chat :avatar-circle="true" v-for="(item,index) in billList" :key="index" :title="formatTime(item.billDate)"
				avatar="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png" :note="`用电量:${item.delUsage} 千瓦时（度）`"
				:to="`/pages/bill/info?bid=${item.billInfoId}`"
				>
				<span style="font-weight: bold;">-{{ item.payAmounts }}元</span>
				</uni-list-chat>
		</uni-list>
	</view>
</template>

<script>
	import {
		getBillListByUserId
	} from '@/api/system/bill'
	export default {
		data() {
			return {
				// 账单列表
				billList: [],
			};
		},
		mounted() {
			console.log("billList...")
			this.getBillList();
		},
		methods: {
			// 格式化时间
			formatTime(time) {
				const date = new Date(time); // 将 ISO 8601 字符串转换为 Date 对象
				const year = date.getFullYear(); // 获取年份
				const month = date.getMonth() + 1; // 获取月份（注意月份是从 0 开始的，所以要加 1）
				return `${year}年${month}月电费账单`;
			},
			// 获取账单列表
			getBillList() {
				const userId = this.$store.state.user.uid;
				getBillListByUserId(userId).then(resp => {
					this.billList = resp
				})

			}
		}
	}
</script>

<style lang="scss">

</style>